package game.efekti;

import util.INIGroup;
import util.Util;
import game.Character;
import game.EffectStage;
import game.Item;
import game.MagicEffect;

public class AttributePlus extends MagicEffect {
	private int atr = 0;
	private int plus = 0;
	
	@Override
	public boolean canHazTip(Item.ItemType tip) {
		if(tip == Item.ItemType.POTION) return false;
		if(tip == Item.ItemType.SPECIAL) return false;
		return true;
	}
	
	@Override
	public void doEffect(Character c1, Character c2) {
		switch (atr)
		{
		case 0:
			c1.setStrength(c1.getStrength() + plus);
			break;
		case 1:
			c1.setDexterity(c1.getDexterity() + plus);
			break;
		case 2:
			c1.setVitality(c1.getVitality() + plus);
			break;
		case 3:
			c1.setIntelligence(c1.getIntelligence() + plus);
			break;
		}
	}

	@Override
	public void generateForLevel(int lvl) {
		atr = Util.getRndInt(0, 3);
		plus = Util.getRndInt((int)(1 + lvl * 0.1), (int)(1 + lvl * 0.4));
	}

	public String toString()
	{
		switch (atr)
		{
		case 0:
			return "+" + plus + " strength";
		case 1:
			return "+" + plus + " dexterity";
		case 2:
			return "+" + plus + " vitality";
		case 3:
			return "+" + plus + " inteligence";
		}
		return "";
	}

	@Override
	public EffectStage getStage() {
		return EffectStage.PreConstantEffect;
	}

	@Override
	public boolean loadFromFile(INIGroup grupa) {
		tag = grupa.getString("Tag");
		atr = grupa.getInteger("Attribute", 0);
		plus = grupa.getInteger("Plus", 0);
		return true;
	}

	@Override
	public void init() {}

	@Override
	public boolean stacksWith(MagicEffect e) {
		if(e instanceof AttributePlus)
			return ((AttributePlus)e).atr == atr;
		return false;
	}

	@Override
	public void absorb(MagicEffect e) {
		if(stacksWith(e))
			plus += ((AttributePlus)e).plus;
	}
}
